<template>
	<view class="page">
		<view class="zy_swiper">
			<view class="lunbo">
				<uv-swiper 
					:list="list" 
					height="224"
					@change="e => current1 = e.current" 
					>
					<template v-slot:indicator>
						<view class="indicator">
							<view class="indicator__dot" 
								v-for="(item, index) in list" 
								:key="index" 
								:class="[index === current1 && 'indicator__dot--active']"
							></view>
						</view>
					</template>
				</uv-swiper>
			</view>
		</view>
	    <view class="zy_notice">
	    	<view class="uni-image"></view>
			<view class="zy_roll">
				<uv-notice-bar   :icon="false" :text="text" direction="column" bgColor="#fff" :disableScroll="disableScroll"  color="#000" url="/pages/art/list"></uv-notice-bar>
			</view>
	    </view>
		<view class="fgs">
			<view @click="TorushClick" class="touming">
				<view class="wenben">
					<view class="pai_y">
						<view class="dy_line"></view>
						<view class="dy_wen">{{rushData.name}}</view>
						<view class="dy_line"></view>
					</view>
					<view class="pai_e">{{rushData.starttime}} - {{rushData.endtime}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {memberInfo} from '@/api/user.js';
	import {fetchRushIndex} from '@/api/rush.js';
	export default {
		data() {
			return {
				list:[
					'https://h5m019abcdefg.jishoufurudonghai.com/uploads/2023-11-08/654a63a818f8a.png',
					'https://h5m019abcdefg.jishoufurudonghai.com/uploads/2023-11-19/2023111909360483.jpg'
				],
				text:["公告"],
				disableScroll:true,
				current1:0,
				rushData:{},
				starttime:"19:00:00"
			
			}
		},
		onLoad() {
			// this.userInfoEvent()
			// fetchRushIndex().then(Response=>{
			// 	this.rushData=Response.data
			// })
		},
		mounted() {
			// fetchRushIndex().then(Response=>{
			// 	this.rushData=Response.data
			// })
		},
		onShow() {
			fetchRushIndex().then(Response=>{
				this.rushData=Response.data
			})
		},
		methods: {
			TorushClick(){
				if(this.rushData.isAuth!='normal'){
					uni.showToast({
						title: "请提交签名并等待客服审核",
						icon:'error',
						duration: 2000
					});
					return
				}
				if(this.rushData.isBank==0){
					uni.showToast({
						title: "请先添加收款方式",
						icon:'error',
						duration: 2000
					});
					return
				}
				if(this.rushData.isAdd==0){
					uni.showToast({
						title: "请先添加收货地址",
						icon: 'error',
						duration: 2000
					});
					return
				}
				
				if(this.rushData.rushswitch==0){
					uni.showToast({
						title: "抢购暂未开放",
						icon: 'error',
						duration: 2000
					});
					return
				}
				const now = new Date(); // 获取当前时间
				let endtime = this.rushData.starttime;
				const [endHour, endMinute, endSecond] = endtime.split(':').map(Number); // 解析出结束时间的时、分、秒
				const endTimestamp = new Date(now.getFullYear(), now.getMonth(), now.getDate(), endHour, endMinute, endSecond).getTime(); // 计算当天的结束时间戳
				const startTimestamp = endTimestamp - 30 * 60 * 1000;
				if (now.getTime() >= startTimestamp) {
					uni.navigateTo({
					  url: '/pages/rush/list'
					});
				} else {
					uni.showToast({
						title: "抢购暂未开放",
						duration: 2000
					});
					return
				}
				
			},
			
			userInfoEvent: function() {
				memberInfo().then(response=>{
					// if(response.code == 1 && response.data.isAuth != "normal"){
					// 	uni.showModal({
					// 		title: "提示",
					// 		content: "请您立即完善实名，并且完成客户签约流程，谢谢",
					// 		showCancel: false,
					// 		success() {
					// 			uni.navigateTo({
					// 				url:"/pages/bonus/smrz"
					// 			})
					// 		}
					// 	})
					// }
					if(response.code == 1){
							if(response.data.isBank != 1 || response.data.isAuth != "normal"){
								uni.showModal({
									title: "提示",
									content: "请先实名并添加收款方式",
									showCancel: true,
								})
							}
					}
				});
			},
		}
	}
</script>

<style>
	.zy_swiper .lunbo{
		width: 100%;
		height: 224px;
		overflow:hidden;
		margin: 0 auto;
	}
	
	.indicator{
		display: flex;
		flex-direction: row;
		justify-content: center;
	}
	.indicator__dot {
		height: 6px;
		width: 6px;
		border-radius: 100px;
		background-color: rgba(255, 255, 255, 0.35);
		margin: 0 5px;
		transition: background-color 0.3s;
		
	}
	.indicator__dot--active{
		background-color: #ffffff;
	}
	.zy_notice{
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		background-color: #ffffff;
		width: 100%;
		color: #333;
		padding: 20px 5px 10px 10px;
	}
	.zy_roll {
	    align-self: flex-start;
	    margin: -10px 0 0 0;
	    font-size: 14px;
	    height: 26px;
	    width: 80%;
	}
	.uni-image{
		width: 80px;
		height: 18px;
		background-image: url(/static/img/user/news.png);
		background-size:100% 100%;
	}
	.fgs{
	    width: 95%;
	    height: 170px;
	    margin: auto;
	    border-radius: 10px;
	    background-size: 100% 100%;
	}
	.touming{
		width: 100%;
		height: 100%;
		background-color: rgba(12, 11, 9, .6);
		border-radius: 10px;
		display: flex;
		text-align: center;
		align-items: center;
		background-image: url(../../static/images/qianggou_b.jpg);
	}
	.wenben{
		width: 100%;
		text-align: center;
	}
	.pai_y{
	    width: 100%;
	    display: flex;
	    margin-bottom: 10px;
	    align-items: center;
	    color: #fff;
	    justify-content: center;
	}
	.dy_line {
	    width: 42px;
	    border-top: #fff solid 1px;
	}
	.dy_wen{
	    margin: 0 10px 0 10px;
	}
	.pai_e{
	    color: #fff;
	}
</style>